package com.huyi.web.service.impl;

import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.huyi.common.annotation.CuratorLock;
import com.huyi.common.annotation.ParamOff;
import com.huyi.common.annotation.RedisLock;
import com.huyi.web.entity.User;
import com.huyi.web.mapper.UserMapper;
import com.huyi.web.service.UserService;

@Service
public class UserServiceImpl implements UserService{

	@Resource
	private UserMapper userMapper;
	
	@Override
	@RedisLock(lockKey = "findUserByLoginId", paramOff = @ParamOff(lockBean = "user1", lockParam = "userId"))
	public User findUserByLoginId(User user1) {
		User user = new User();
		user.setLoginId(user1.getLoginId()+UUID.randomUUID());
		user.setPassword("1111");
		userMapper.insert(user);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return userMapper.findUserByLoginId(user1.getLoginId());
	}

	@Override
	@CuratorLock(pathSuffix = "20181120")
	public User findUserByLoginId1(User user1) {
		User user = new User();
		user.setLoginId(user1.getLoginId()+UUID.randomUUID());
		user.setPassword("1111");
		userMapper.insert(user);
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return userMapper.findUserByLoginId(user1.getLoginId());
	}

	@Override
	public List<User> queryUserInfoByUserId(String userId) {
		return userMapper.queryUserInfoByUserId(userId);
	}

	@Override
	public List<User> queryAllUserList() {
		return userMapper.selectList(null);
	}

}
